package com.kingdee.eas.scm.im.inv.client;


import java.awt.Color;
import java.text.MessageFormat;

import com.kingdee.bos.ctrl.kdf.table.KDTSelectManager;
import com.kingdee.bos.ctrl.kdf.table.KDTable;
import com.kingdee.eas.framework.client.FindListEvent;
import com.kingdee.eas.framework.client.IFindListListener;
import com.kingdee.eas.framework.client.ListUI;
import com.kingdee.eas.framework.client.service.TableLocationServer;
import com.kingdee.eas.framework.util.ConfigParams;
import com.kingdee.eas.util.client.EASResource;
import com.kingdee.eas.util.client.MsgBox;


public class FindKdtenrtyListener implements IFindListListener {


	
    public FindKdtenrtyListener(KDTable tblMain1)
    {
        server = getTableLocationServer();
        tblMain = tblMain1;
        server.setTblMain(tblMain);
        server.setFirstLocate(true);
    }

    protected TableLocationServer getTableLocationServer()
    {
        return new TableLocationServer();
    }

    private com.kingdee.eas.framework.client.service.TableLocationServer.LocateParam getConfigParam(FindListEvent e)
    {
        config_params = new ConfigParams();
        config_params.addBooleanParam("is_match", e.isIsMatch());
        config_params.addIntParam("find_direction", e.getFindDeration());
        config_params.addBooleanParam("has_query_pk", false);
        int max_row = tblMain.getRowCount();

        config_params.addIntParam("row_count", max_row);
        return new com.kingdee.eas.framework.client.service.TableLocationServer.LocateParam(e.getSearch(), e.getPropertyName(), config_params);
    }

    public void FindNext(FindListEvent e)
    {
        param = getConfigParam(e);
        com.kingdee.eas.framework.client.service.TableLocationServer.LocateResult result = server.locate(param);
        if(result == com.kingdee.eas.framework.client.service.TableLocationServer.LocateResult.nullLocateResult)
            return;
        if(result.isLocateSuccess())
        {
            tblMain.getSelectManager().setSelectMode(KDTSelectManager.ROW_SELECT);
            tblMain.getSelectManager().select(result.getLocateRow(), 5);
            
            ///Color color = new Color(250,201,214);
            //tblMain.getSelectManager().setSelectColor(color);
            

			//tblMain.getRow(result.getLocateRow()).getStyleAttributes().setBackground(Color.RED); java.awt.Color[r=252,g=251,b=223]
            //Color color = new Color(252,251,223); //= java.awt.Color[r=252,g=251,b=223]; java.awt.Color[r=146,g=206,b=91]
            //tblMain.getColumn(5).getStyleAttributes().setground(color);
            //tblMain.getCell(result.getLocateRow(), 5).getStyleAttributes().setBackground(Color.RED);
            tblMain.getLayoutManager().scrollRowToShow(result.getLocateRow());
        } else
        if(result.getLocateRowCount() == 0)
        {
            String str;
            if(e.getFindDeration() == 2)
                str = locateLast;
            else
                str = locateFirst;
            MsgBox.showInfo(tblMain, EASResource.getString("com.kingdee.eas.framework.FrameWorkResource." + str));
        } else
        {
            String str;
            if(e.getFindDeration() == 2)
                str = "Msg_LocateLast_end";
            else
                str = "Msg_LocateFirst_end";
            String msg = EASResource.getString("com.kingdee.eas.framework.FrameWorkResource." + str);
            Object objs[] = {
                new Integer(result.getLocateRowCount())
            };
            msg = MessageFormat.format(msg, objs);
            MsgBox.showInfo(tblMain, msg);
        }
        server.setFirstLocate(false);
    }
    
    private TableLocationServer server;
    private com.kingdee.eas.framework.client.service.TableLocationServer.LocateParam param;
    private ConfigParams config_params;
    //private ListUI list_ui;
    private KDTable tblMain;
    private static String locateFirst = "Msg_LocateFirst";
    private static String locateLast = "Msg_LocateLast";
	public void FindClose(FindListEvent findlistevent) {

		
	}
}
